﻿using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using WorseGame.Common.Configs;

namespace WorseGame.Common.GlobalTiles
{
    public class WorseTile : GlobalTile
    {
        public override bool CanDrop(int i, int j, int type)
        {
            if (TileConfig.Instance.TileCanDrop)
            {
                if (Main.rand.NextFloat() < 0.1f)
                {
                    return false;
                }
            }
            return base.CanDrop(i, j, type);
        }
        public override void NearbyEffects(int i, int j, int type, bool closer)
        {
            if (TileConfig.Instance.CampfireBurning)
            {
                if (type == TileID.Campfire)
                {
                    Vector2 campfireCenter = new(i * 16 + 8, j * 16 + 8);
                    for (int p = 0; p < Main.maxPlayers; p++)
                    {
                        Player player = Main.player[p];
                        if (player.active && !player.dead)
                        {
                            float distance = Vector2.Distance(player.Center, campfireCenter);
                            if (distance < 60f)
                            {
                                player.AddBuff(BuffID.OnFire, 90);
                            }
                        }
                    }
                }
            }
          
        }       
    }
}
